package day03;

import java.io.IOException;
import java.net.URLEncoder;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DemoEncoding extends HttpServlet{
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//		String s = "中";
//		
//		byte[] bytes = s.getBytes("utf-8");
//		for (byte b : bytes) {
//			System.out.println(b);
//		}
//		
//		byte[] bytes2 = s.getBytes("iso-8859-1");
//		for (byte b : bytes2) {
//			System.out.println(b);
//		}
		
		byte[] bytes = {(byte) 0xE5, (byte)0xBC, (byte)0xA0};
		String s2 = new String(bytes, "iso-8859-1");
		
		byte[] bytes2 = s2.getBytes("iso-8859-1");
		for (byte b : bytes2) {
			System.out.println(Integer.toHexString(b));
		}
		
		String s3 = new String(bytes2, "utf-8");
		System.out.println(s3);
		
		System.out.println(URLEncoder.encode("张三", "utf-8"));
	}
}
